package com.zam.utils.DateUtil;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @Author talent_dog
 * @Date 2024/1/4 21:29
 * @Version 1.0
 */
public class DateTransformUtil {
    public static String formatDataTime(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String format = simpleDateFormat.format(date);
        return format;
    }
    public static String formatDataTime2(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        return format;
    }

    public static String formatData(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        return format;
    }

    public static String formatTime(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH-mm-ss");
        String format = simpleDateFormat.format(date);
        return format;
    }


    public static LocalDateTime stringToData(String date) throws Exception {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = format1.parse(date);
        Instant instant = parse.toInstant();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

        return localDateTime;
    }
    public static LocalDateTime stringToDataTime(String date) throws Exception {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = format1.parse(date);
        Instant instant = parse.toInstant();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

        return localDateTime;
    }
    public static LocalDateTime stringToDataSimple(String date) throws Exception {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM");
        Date parse = format1.parse(date);
        Instant instant = parse.toInstant();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

        return localDateTime;
    }

}